package cosplay.Services;

import java.io.File;
import java.sql.Timestamp;

import cosplay.Beans.Users;

public class UserServices {
	//return null if unavailable or initialized competition
	public static Users UserVerify(Users user)
	{
		return cosplay.Services.UserServices.UserVerify(user, "E:/preview_test.jpg");
	}
	//return null if unavailable or initialized competition with defaultimages
	public static Users UserVerify(Users user,String defaultFile)
	{
		if((user.getUserName()==null)||(user.getUserName()==""))
			return null;
		if((user.getPassWord()==null)||(user.getPassWord()==""))
			return null;
		if((user.getUserRole()==null)||(user.getUserRole()==""))
			user.setUserRole("ROLE_USER");
		if(user.getAddress()==null)
			user.setAddress("");
		if(user.getBirthday()==null)
			user.setBirthday(null);
		if(user.getCountry()==null)
			user.setCountry("");
		if(user.getDescription()==null)
			user.setDescription("");
		if((user.getEmail()==null)||(!user.getEmail().contains("@"))||(!user.getEmail().contains(".")))
			user.setEmail("");
		if(user.getHeadImage()==null)
			user.setHeadImage(cosplay.Services.FileServices.getBytesFromFile(new File(defaultFile)));
		if(user.getLastLogIn()==null)
			user.setLastLogIn(new Timestamp(System.currentTimeMillis()));
		if(user.getLastLogIP()==null)
			user.setLastLogIP("");
		if(user.getNickName()==null)
			user.setNickName(user.getUserName());
		if(user.getTel()==null)
			user.setTel("");
		if(user.getGender()==null)
			user.setGender("");
		if(user.getCity()==null)
			user.setCity("");
		return user;
	}

}
